<extend name="Common@Layout:layui-admin" />
<block name="title">
    <title>用户列表</title>
</block>
<block name="style">
    <style>
        body {
            padding: 10px;
        }
        
        .layui-table td,
        .layui-table th {
            font-size: 12px;
        }
    </style>
</block>

<block name="main">
    <div class="my-btn-box">
        <span class="fl">
	        <a class="layui-btn btn-add btn-default" onclick="open_iframe_dialog('{:U('edit')}','添加',['100%','100%'],0)" id="btn-add-article">添加</a>
	    </span>
        <span class="fr">
            <php>$dUrl = $_GET['role'] ? '/admin/users/index/role/'.$_GET['role'] : '/admin/users/index';</php>
            <form class="layui-form" action="{$dUrl}" method="get">
                <span class="layui-form-label">搜索条件：</span>

        <div class="layui-input-inline" style="width:100px;">
            <php>
                $types = array( 'uid'=>'uid','p1'=>'客户代码', 'username' => '用户名', 'email' => 'Email', 'mobile' => '手机', 'realname' => '真实姓名', 'company' => '公司名', 'nickname' => '昵称' );
            </php>
            <select name="search_type" lay-verify="required">
                        <foreach name="types" item="vo" key="k">
                        <option value="{$k}" <if condition="$_GET['search_type'] eq $k ">selected</if>>{$vo}</option>
                        </foreach>
                    </select>
        </div>
        <div class="layui-input-inline" style="width:250px;">
            <input type="text" name="search_keyword" value="{$_GET['search_keyword']}" autocomplete="off" placeholder="请输入搜索条件" class="layui-input">
        </div>
        <button class="layui-btn mgl-20">查询</button>
        </form>
        <?php
            $conditionStr = ""; 
            $strToRed = ""; 
            if($_GET['search_type'] && $_GET['search_keyword']){ 
                $condition = array( $_GET['search_type'] => $_GET['search_keyword'] ); 
                $strToRed = 'param-'.$_GET['search_type'].":".$_GET['search_keyword'];
            }

            if($_GET['role'] != ''){
                $condition['role'] = $_GET['role'];
            }
            
            $conditionStr = "condition=".condition_to_str($condition); 

        ?>
            </span>

    </div>
    <div class="layui-btn-group">
        <php>$roles = D('AuthGroup')->where('status=1')->getField('group,title');</php>
        <a href="/admin/users/index" class="layui-btn layui-btn-small <if condition=" $_GET[ 'role'] neq '' ">layui-btn-primary</if>">全部</a>
        <foreach name="roles" item="vo" key="k">
            <a href="/admin/users/index/role/{$k}" class="layui-btn layui-btn-small <if condition=" $_GET[ 'role'] neq $k or !$_GET[ 'role'] ">layui-btn-primary</if>">{$vo}</a>
        </foreach>
    </div>
    <div class="layui-form datashow" data-url="{:U('getdata')}" data-to-red="{$strToRed}" data-condition="{$conditionStr}" data-p="1" data-row="10">
        <table class="layui-table">
            <colgroup>
                <col width="50">
                <col>
                <col>
                <col>
                <col>
                <col>
                <col>
                <col>
                <col>
                <col>
                <col>
                <col width="180">
            </colgroup>
            <thead>
                <tr>
                    <th><input type="checkbox" name="" lay-skin="primary" lay-filter="allChoose"></th>
                    <th>uid</th>
                    <th>用户名</th>
                    <th>昵称</th>
                    <th>姓名</th>
                    <th>Email</th>
                    <th>手机</th>
                    <th>公司</th>
                    <th>等级</th>
                    <th>状态</th>
                    <th>操作</th>
                </tr>
            </thead>
            <tbody class="data"></tbody>
        </table>
        <div class="page"></div>
        <script class="data-tpl" type="text/html">
            {{# layui.each(d, function(index, item){ }}
            <tr>
                <td><input type="checkbox" name="ids[]" value="{{item.uid}}" lay-skin="primary">
                    <div class="layui-unselect layui-form-checkbox" lay-skin="primary"><i class="layui-icon"></i></div>
                </td>
                <td class="param-uid">{{item.uid}}</td>
                <td class="param-username">{{item.username}}</td>
                <td class="param-nickname">{{item.nickname || '无'}}</td>
                <td class="param-realname">{{item.realname || '无'}}</td>
                <td class="param-email">{{item.email || '无'}}</td>
                <td class="param-mobile">{{item.mobile || '无'}}</td>
                <td>{{item.level}}</td>
                <td class="param-p1">{{item.p1 || '空'}}</td>
                <td>
                    {{# if(item.status == 1){ }}正常 {{# } }} {{# if(item.status == 0){ }}未激活 {{# } }} {{# if(item.status == -1 ){ }} 禁用 {{# } }}
                </td>
                <td>
                    <button onclick="open_iframe_dialog('/admin/users/edit/uid/{{item.uid}}','修改用户',['100%','100%'],0)" class="layui-btn layui-btn-small layui-btn-normal">修改</button>
                    <!--<a href="javascript:;" onclick="open_iframe_dialog('/shipment/usertpl/editbyuid/uid/{{item.uid}}','编辑分配模板',['600px','350px'],0)" class="layui-btn layui-btn-small layui-btn-normal">分配模板</a>-->
                    <a href="javascript:;" data-url="/admin/users/del/ids/{{item.uid}}" class="layui-btn layui-btn-danger layui-btn-small mini_del">删除</a>
                </td>
            </tr>
            {{# }); }} {{# if(d.length === 0){ }} --- No Data --- {{# } }}
        </script>
    </div>
</block>

<block name="script">
    <script>
        var roleJson = <?php echo json_encode(C('USER_ROLES'));?>;
        var curRole = '{$_GET["role"]}';

        function getRole(name) {

            if (!name) {
                return "非法用户";
            } else {
                if (typeof(roleJson[name]) == "undefined") {
                    return "非法用户";
                }
                if (curRole == name) {
                    return '<span style="color:red">' + roleJson[name].NAME + '</span>';
                }
                return roleJson[name].NAME;
            }
        }
    </script>
</block>